A total of 1077 characters, expected to take 3 minutes to complete reading.
Why Linux System Backup?
Using Linux system for daily work, data security is one of our most concerned issues. Unlike Windows systems, the backup and recovery process for Linux systems is more flexible and does not rely on third-party tools. The backup of Linux system is easier and more powerful. You only need to use the tools that come with the system--
tar
command to complete a full system backup.
1. backup system
Here we take the centos system as an example.
1. Switch to the folder to be backed up
First switch to the root user to ensure that the backup process is not restricted, enter the command sudo su
You can.
Then enter the place where you want to back up. Since we want to back up the system, we can directly enter the home directory here.cd /
.
Namely:
sudo su && cd /
2. Backup with tar
tar is a commonly used packing compression command, so you can also back up the system.
When backing up, we should also pay attention to excluding some folders, such as recycle bins, etc. Here we use --exclude
to exclude these folders. Here is an example of backing up the entire system with gzip:
tar cvpzf backup.tar.gz
--exclude=/media
--exclude=/proc
--exclude=/lost+found
--exclude=/mnt
--exclude=/sys
--exclude=backup.tar.gz
./
# 说明:# cvpfz:这些选项分别表示创建新归档文件、保留文件权限、使用 gzip 压缩。# backup.tar.gz:这是生成的备份文件名称。# ./:表示需要备份的目录,这里是整个文件系统。# --exclude=:用来排除一些不需要备份的目录,如 /proc、/sys 等。
If you have higher requirements for compression ratio, you can also use Bzip2 compression:
tar cvpjf backup.tar.bz2
--exclude=/media
--exclude=/proc
--exclude=/lost+found
--exclude=/mnt
--exclude=/sys
--exclude=backup.tar.bz2
./
2. Recovery System
1. Also enter the directory to be restored
Switch to root usersudo su
, and then enter the directory to be restoredcd /
.
sudo su && cd /
2.tar unzip and restore
If using gzip compression:
tar xvpfz backup.tgz -C /
If using Bzip2 compression:
tar xvpfj backup.tar.bz2 -C /
However, it should be noted that decompression here will overwrite all previous files, that is, restore the state of all files at that time.
After the decompression is complete, you may also need to restore folders that have not been backed up before, such as the Recycle Bin, etc.
mkdir /proc /lost+found /mnt /sys /media
3. Restart the system
After completing the above steps, restart the system and you will find that all data and system settings have been restored to the state they were in at the time of backup.
reboot